#include "lvgl.h"
#include "ui_app.h"
#include "cmsis_os.h"
#include "ui_home_page.h"
#include "ui_test.h"
#include "driver.h"

osThreadId_t ui_main_task_handle;
const osThreadAttr_t ui_main_task_attributes = {
  .name = "ui_main",
  .priority = (osPriority_t) osPriorityHigh,
  .stack_size = 512 * 4
};

osThreadId_t ui_update_task_handle;
const osThreadAttr_t ui_update_task_attributes = {
  .name = "ui_update",
  .priority = (osPriority_t) osPriorityHigh,
  .stack_size = 512 * 4
};


void ui_main(void* pv)
{
    home_page_create(lv_scr_act());

    while(1)
    {
        osDelay(1000);
    }
}

void ui_update(void*pv)
{
    imu_t val;
    pressure_t pressure;
    uint32_t pedometer;
    RTC_DateTypeDef sDate;
    RTC_TimeTypeDef sTime;
    float voltage;
    while(1)
    {
        get_imu_val(&val);
        get_pressure_val(&pressure);
        date_time_get(&sDate, &sTime);
        pedometer = get_pedometer_val();
        voltage = get_battery_voltage();

        set_height(pressure.altitude);
        set_pedometer(pedometer);
        set_date(sDate.Year, sDate.Month, sDate.Date);
        set_time(sTime.Hours, sTime.Minutes);
        set_voltage(voltage);
        osDelay(10);
    }
}

void ui_task_init(void)
{
    ui_main_task_handle = osThreadNew( ui_main, NULL, &ui_main_task_attributes);
    ui_update_task_handle = osThreadNew( ui_update, NULL, &ui_update_task_attributes);
}

